#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

const int maxn = 1e5 + 500;
int a[maxn], n;

//T(n)=2*T(n/2)+O(n)=>T(n)=O(nlogn)
int f(int a[], int left, int right) {
    if (left == right) return a[left];
    int mid = (left + right) / 2;
    int fleft = f(a, left, mid);
    int fright = f(a, mid + 1, right);
    int bleft = a[mid], sleft = 0;
    for (int i = mid; i >= left; i--) {
        sleft += a[i];
        bleft = max(bleft, sleft);
    }
    int bright = a[mid + 1], sright = 0;
    for (int i = mid + 1; i <= right; i++) {
        sright += a[i];
        bright = max(bright, sright);
    }

    return max(fleft, max(fright, bleft + bright));
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> a[i];
    cout << f(a, 1, n) << endl;
    return 0;
}


